
function OnSendSms(text)
	ssp.log(DEBUG, "smsno=" .. smsno .. " text=" .. text);
	ssp.sendsms(tostring(smsno), tostring(text));
end

function OnReCheckSendSms(text)
	"\c\s[20]「".. text .."」 这样回复，可以吗？\n\q[可以,OnSendSms,".. text .."]    \q[重新输入,OnSmsRe]"
end

function OnReadNewSms()
	OnMoveSms(1, -1);
end

function OnReadSms()
	tdata = ssp.getthreads();
	thread_count = tdata:getCount();
	thread_read = 0;
	ssp.log(DEBUG, "thread_read=" .. thread_read);
	if(thread_count == tonumber("0")) then
	 noSms();
	else
	 displayThread();
	end;
end

function displayThread()
	if (thread_read >= thread_count) then
		thread_read=0;
	end
	if(tdata:moveTo(thread_read)) then
		"\c\s[20]" .. tostring(ssp.tocontact(tdata:getAddress())) .. "\n"
		"最后在" .. tdata:getDate("yyyy年MM月dd日 HH:mm") .. "时\n"
		"说:" .. tdata:getMessage() .. "\n"
		"\q[查看,OnMoveSms,0," .. tdata:getId() .. "]		\q[下一条,displayThread]"
		thread_read = thread_read + 1;
	else
		thread_read = 0;
	end
	
end

function displayThread1()
	if (thread_read >= thread_count) then
		thread_read=0;
	end
	
	local max_read = 0;
	if (thread_count < 5) then
		max_read = thread_count;
	else
		max_read = thread_read + 5;
	end
	"\c"
	for i=thread_read,max_read-1 do
		if(tdata:moveTo(i)) then
			"\q[" .. tostring(ssp.tocontact(tdata:getAddress())) .. "说:" .. tdata:getMessage() .. ",OnMoveSms,0," .. tdata:getId() .. "]\n"
			
		else
			break;
		end
	end
	thread_read = thread_read + 5;
	"\n\q[翻页,displayThread]"
	
end

function displaySms()
	if(smsdata:move()) then
		ssp.log(DEBUG, smsdata:getid() .. " " .. smsdata:getAddress() .. " " .. smsdata:getBody() .. " " .. smsdata:getRead() .. " " .. smsdata:getDate("yyyy年 MM月 dd日 HH时 mm分"));
		"\c\s[26]" .. ssp.tocontact(smsdata:getAddress()) .. "\n"
		"在" .. smsdata:getDate("yyyy年MM月dd日 HH:mm") .. "时\n"
		"说:" .. smsdata:getBody() .. "\n"
		"\n\q[回复,OnSmsRe]		\q[删除,OnDelSms]		\s[0]"
		"\q[下一条,displaySms]"
		ssp.setread(tostring(smsdata:getid()));
	else
		noSms();
		return;
	end
	smsno = smsdata:getAddress();
	smsid = smsdata:getid();
	
end

function noSms()
	"\c\s[26]没有短信可读了哦\w8~~\w8~~\s[0]"
	
end

function OnMoveSms(type,thread)
	ssp.log(DEBUG, "type=" .. type .. " thread=" .. thread);
	smsdata = ssp.readsms(type,thread);
	displaySms();
end

function OnDelSms()
	if (smsid ~= nil) then
		ssp.delsms(smsid);
	end
	displaySms();
end

function OnReceiverSms(sender,message)
	local str = "收到来自: " .. ssp.tocontact(sender) .. " 短信";
	ssp.notify(str, "", "sms");
end

function OnSmsRe()
	"\![open,inputbox,OnReCheckSendSms]\e"
	
end


